﻿using LeEdu.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LeEdu.DAL.DataAccess
{
    using ServiceStack.OrmLite;

    public class FileDal:GenericBaseDAL<File>
    {
        /// <summary>
        /// 根据课程Id查询文件列表
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public List<File> SelectListByCourseId(Guid cid)
        {
            using (var cnn=DbConnection)
            {
                var sql = cnn.From<File>()
                    .Where(m => m.CourseId == cid);
                return cnn.Select(sql);
            }
        }


        public File SelectFileByFileId(Guid cid)
        {
            using (var cnn=DbConnection)
            {
                var sql = cnn.From<File>()
                    .Where(m => m.Id == cid);
                List<File> list = cnn.Select(sql);
                return list[0];
            }
        }
        /// <summary>
        /// 根据课程Id和文件类型查询文件列表
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public List<File> SelectListByCourseIdAndDocType(Guid cid)
        {
            using (var cnn = DbConnection)
            {
                var sql = cnn.From<File>()
                    .Where(m => (m.CourseId == cid && m.Extension == ".mp4"));
                return cnn.Select(sql);
            }
        }
    }
}
